﻿
Namespace LightSwitchApplication

    Public Class ListAssets


        Private Sub ListAssets_Saving(ByRef handled As Boolean)
            ' Write your code here.
            With Me.MainAssetsTables.SelectedItem
                .LastModified = Now
                .LastModifiedBy = Application.Current.User.FullName
            End With
        End Sub

        Sub changeDisplayName()
            If Not MainAssetsTables.SelectedItem Is Nothing Then
                Me.DisplayName = "Asset : " & MainAssetsTables.SelectedItem.Assetno
            End If

        End Sub

        Private Sub MainAssetsTables_SelectionChanged()
            changeDisplayName()
            Dim depreciationYears As Integer = 0
            Dim disposeddateSold As Date = Nothing
            Dim depreciationMethod As Integer = 0
            Dim totalAssetAmount As Decimal = 0

            If Not MainAssetsTables.SelectedItem Is Nothing Then



                If Not Me.MainAssetsTables.SelectedItem.Category Is Nothing Then
                    depreciationMethod = MainAssetsTables.SelectedItem.Category.DepreciationMethod
                End If
                If Me.MainAssetsTables.SelectedItem.Category Is Nothing Then
                    depreciationYears = 0
                ElseIf Me.MainAssetsTables.SelectedItem.Category.Years Is Nothing Then
                    depreciationYears = 0
                Else
                    depreciationYears = Me.MainAssetsTables.SelectedItem.Category.Years
                End If

                If Me.MainAssetsTables.SelectedItem.DisposedAsset Is Nothing Then
                    disposeddateSold = Now
                ElseIf Me.MainAssetsTables.SelectedItem.DisposedAsset.DateSold Is Nothing Then
                    disposeddateSold = Now
                Else
                    disposeddateSold = Me.MainAssetsTables.SelectedItem.DisposedAsset.DateSold
                End If

                totalAssetAmount = If(Me.MainAssetsTables.SelectedItem.AssetAmount > 0 _
                                     , Me.MainAssetsTables.SelectedItem.AssetAmount _
                                     , If(Me.MainAssetsTables.SelectedItem.BaseCost Is Nothing, 0, Me.MainAssetsTables.SelectedItem.BaseCost) + If(Me.MainAssetsTables.SelectedItem.VAT Is Nothing, 0, Me.MainAssetsTables.SelectedItem.VAT))

                ' deprec = ComputeDepreciationClass.ComputeDepreciation(depreciationYears, disposeddateSold, totalAssetAmount, Me.MainAssetsTables.SelectedItem.DateAcquired, depreciationMethod)
            End If
        End Sub

        
    End Class

End Namespace
